<template>
	<view>
		<uni-popup ref="reserve" zindex type="bottom" borderRadius="16rpx 16rpx 0 0" :safeArea="false">
			<view class="carListBox" @touchmove.stop.prevent="">
				<view class="" style="width: 100%;height:2rpx"></view>
				<view class="uni-dialogCon uni-border-no pading-discount">
					<view class="belivery-title">{{props.type=='single'&&navClass==1?'请选VIP专区券':'请选择优惠券'}}</view>
				</view>
				<view class="tabs_box">
					<!-- single提交订单 ，one只展示选中项 -->
					<tabs ref="tabsRef" :list="tablist" :type="props.type" marright="5rpx"
						:current="navClass" activeWeight='400' @tabItemClick="tabSelect" fontSize="32rpx"
						activeColor="#000" activeBarColor="#53A87F" barMargin="10"></tabs>
				</view>
				<block  v-for="(fitem,findex) in tablist" :key="findex" >
					<scroll-view v-if="navClass==findex" scroll-with-animation @scrolltolower="scrolltolower" scroll-y="true" class="uni-bar-wbg fullw">
						<view class="uni-bar-w cu-bar-flex p_rlt  popup-Discount-overflowY"
							:class="{'padding-bottom-xl':navClass==1}">
							<empty positions="absolute" :empty="fitem.loaded&&fitem.list.length<=0" :zIndexs="100"
								:imgUrl="'https://cdn-static.yekjx.com/'+'food/empty/images/empty_ico04.png'"
								content="暂无数据"></empty>
							<!-- <view class="cu-bar-flex-left" v-for="(item,index) in seletDelivery" @tap="seleData(index,id)" :class="{ active: item.status }" :key="item.id">
							    <text>{{item.name}}</text>
							    <view v-if="item.status" class="icon"><text style="color: #53A87F;" class="text-gray cuIcon-check"></text></view>
							  </view> -->
							<block v-for="(item,index) in fitem.list" :key="index">
								<!-- 代金券--s -->
								<view v-if="navClass==0" class="cu-bar-yhj point" @click.stop="clipCoupons(item)">
									<view class="cu-bar-yhj-left">
										<view class="cu-bar-yhj-Pic">
											<view class="cu-bar-yhj-PicStyle">
												{{ item.coupon_type_two=='970'?parseRate(item.par_value):item.ncoupon_money }}
												<text v-if="item.coupon_type_two=='970'" class="cu-bar-yhj-PicZk">折</text>
												<text v-else class="cu-bar-yhj-PicZk">元</text>
											</view>
											<view v-if="item.vdesc" class="cu-bar-yhj-min"><text>{{ item.vdesc }}</text>
											</view>
										</view>
										<view class="cu-bar-yhj-left-text">
											<text class="cu-bar-yhj-title">{{ item.vname||'' }}</text>
											<view class="flex justify-between align-center">
												<text
													class="cu-bar-yhj-left-time">有效截止时间{{!item.vend_date?'':`${item.vend_date.slice(0, 4)}.${item.vend_date.slice(4, 6)}.${item.vend_date.slice(6, 8)}` }}</text>
												<view v-if="usableCount>0" class="cu-bar-yhj-right">
													<text class="text-xll margin-right-xs"
														:class="item.select?'cuIcon-roundcheckfill':'cuIcon-round'"
														:style="{color:item.select?'#2CAC58':'#999'}"></text>
												</view>
											</view>
					
											<view class="padding-top-xs">
												<view class="flex justify-between align-center"
													:class="{justiftRight :item.ttyy == '0'}">
													<text v-if="item.ttyy" class="ttyyTextStyle">{{item.ttyyText}}</text>
													<text class="cu-bar-yhj-left-rule padding-tb-sm"
														@click.stop="showMore(item,['fade', 'slide-top'])">详细说明<text
															class="lg text-gray cuIcon-unfold margin-left-xs inblcok"
															:class="{'routerHover': item.show}"></text></text>
												</view>
												<!--  <uni-transition custom-class="transition"  :mode-class="modeRuleClass" :styles="styles" :duration="100" :show="item.show"> -->
												<view class="rule-con-ul">
													<view class="rule-con" :class="{activeWy : item.show}">
														限会员日当天门店使用，使用范围：颐而康精选商城、小颐有约、炖大侠平台。
													</view>
												</view>
												<!-- </uni-transition> -->
											</view>
											<!-- <view class="rule-con" v-if="item.show " :class="{ ruleActive: item.show }">
								             限会员日当天门店使用，使用范围：颐而康精选商城、小颐有约、炖大侠平台。
								         </view> -->
										</view>
									</view>
								</view>
								<!-- 代金券-e -->
								<!-- vip券-s -->
								<view v-else class="cu-bar-yhj">
									<view class="cu-bar-yhj-left">
										<view class="cu-bar-yhj-Pic">
											<view class="cu-bar-yhj-PicStyle">
												{{ item.faceMoney }}
												<!-- <text v-if="!item.type" class="cu-bar-yhj-PicZk">折</text> -->
												<text class="cu-bar-yhj-PicZk">元</text>
											</view>
											<!-- <view v-if="item.content" class="cu-bar-yhj-min"><text>{{ item.content }}</text></view> -->
										</view>
										<view class="cu-bar-yhj-left-text rtvbx">
											<!-- <view class="text-lg text-c6">{{ item.title }}</view> -->
											<view class="cu-bar-yhj-title  cu-bar-yhj-titleNew">
												<!-- {{ `面额${item.subMoney}元*${item.maxNum}张` }} -->
												<text class="text-lg text-c6">x</text>
												{{ `${item.storeNums}张` }}
											</view>
											<view class="">
												<view class="flex justify-between align-center">
													<!-- <text v-if="item.ttyy" class="ttyyTextStyle">{{item.ttyyText}}</text> -->
													<text class="cu-bar-yhj-left-rule cu-bar-yhj-left-ruleckmx"
														@click="tapCheckDetail(item.faceMoney)">查看明细<text
															class="lg text-gray cuIcon-unfold margin-left-xs inblcok"></text></text>
												</view>
												<!--  <uni-transition custom-class="transition"  :mode-class="modeRuleClass" :styles="styles" :duration="100" :show="item.show"> -->
												<view class="rule-con-ul">
													<view class="rule-con" :class="{activeWy : item.show}">
														限会员日当天门店使用，使用范围：颐而康精选商城、小颐有约、炖大侠平台。
													</view>
												</view>
												<!-- </uni-transition> -->
											</view>
										</view>
									</view>
									<view class="flex justify-between align-center selcbx padding-right"
										:class="{'justifyEend' : item.selectNums *  item.faceMoney == 0}">
										<!-- v-if="props.type == 'menu'&&vipCountData.canUse&&fitem.loaded" -->
										<block v-if="canUseVip">
											<view class="yxuanText" v-if="item.selectNums *  item.faceMoney > 0">
												已选:<text>{{ item.selectNums *  item.faceMoney}}</text>元
											</view>
											<view class="flex align-center">
												已选 <uni-number-box @change="changeNum" v-model="item.selectNums" nstash
													:max="item.storeNums" :min="0"/> <text class="text-c9">张</text>
											</view>
										</block>
					
									</view>
								</view>
								<!-- vip券-e -->
							</block>
							<!-- <uni-load-more v-if="props.type=='menu'&&usableCount<=0&&fitem.loaded" :status="loadStatus" iconType="circle"></uni-load-more> -->
						</view>
					</scroll-view>
				</block>
				

				<view class="discount-footer">
					<view class="discount-footer-l padding-tb-sm padding-right-xs" @click.stop="tapShowSelc">
						<block v-if="tablist[navClass].loaded">
							<view v-if="navClass==1&&vcouponDetail.totalPrice<=0" class="text-c9">
								未添加VIP商品
							</view>
							<view v-else>
								<text class="discount-c-r text-bold">{{ navClass==0?curSolve.curCoupon.cId&&props.coupUseMoney>0?'已选1张':'':'已选'+vipCountData.totalNum+'张' }}</text>
								<!-- vipCountData.canUse -->
								<text v-if="vipCountData.totalMoney>0&&navClass==1"
									class="text-nred text-bold padding-left-sm">{{vipCountData.totalMoney}}元</text>
							</view>
						</block>

					</view>
					<view class="discount-footer-r">
						<text class="sub_btn" @click.stop="confirm">确定</text>
					</view>
				</view>
				<view class="tip-con flex align-center posi-tip" v-if="navClass==1">
					<text class="lg text-gray cuIcon-infofill cuIcon-infofill-style"></text>
					<text class="font-infofill">券不找零，可叠加，专区内商品自动勾选使用 。</text>
				</view>
			</view>
		</uni-popup>
		<!-- vip已选 -->
		<scoupon ref="slecmd"></scoupon>
		<!-- vip详情 -->
		<vcdetail ref="vcdetmd"></vcdetail>
	</view>
</template>

<script setup lang="ts">
	import { ref, defineEmits, computed, onMounted, nextTick, watchEffect } from 'vue';
	import tabs from '@/components/comtabs/comtabs.vue';
	import scoupon from "./selecedCoup.vue";
	import vcdetail from "./vipCoupDetail.vue";
	import { showLoading, hideLoading } from '@/utils/helper';
	import mApi from "@/utils/mapi";
	import { getAutoCoupon, usableCouponList, getVipAccount, getCouponList, totalCouponAmount } from '@/api/vmeitime-http/index.js';
	import { useCartStore } from '@/stores/cartStore';
	import { useShopStore } from '@/stores/shopStore';
	const shopStore = useShopStore();
	const cartStore = useCartStore();
	const props = defineProps({
		nparam: {
			type: Object,
			default: () => {
				return {};
			},
		},
		coupUseMoney:{
			type:Number,
			default:1
		},
		type: {
			type: String,
			default: ''
		}
		// vipDis: {
		// 	type: Object,
		// 	default: () => {
		// 		return { money: 0 };
		// 	},
		// }
	});
	const sellMemberInfo=ref({
		ids:""
	})
	const dataType = ref('')
	const emit = defineEmits(["modelClose", "updateValueFn", "change"])
	const reserve = ref()
	const tabsRef = ref()
	const slecmd = ref()//已选专区券弹窗
	const vcdetmd = ref()//专区券详情弹窗

	// const tipFlag = ref(null)

	const tablist = ref([
		// {
		// 	name: "全部"
		// }, 
		{
			id: '0',
			name: "代金券",
			loaded: false,
			list: []
		}, {
			id: '1',
			name: "VIP专区券",
			loaded: false,
			// tip: '累计330元享8.5折',
			list: []
		}
	])
	const discountData = ref([])
	onMounted(() => {
		// initCoups()//暂
	})
	// const couponParam = computed(() => {
	// 	return props.nparam.value;
	// })
	const curParam = ref()
	watchEffect(() => {
		curParam.value = props.nparam
		console.log('watef', props.nparam)
	})

	const curSolve = ref<any>({
		curCoupon: {},
		curVCoupon: {},
	})
	// const initCoups = (source : string = '') => {
	// 	//暂
	// 	if (source == 'init') {
	// 		// console.log('cmodnparam',props.nparam,couponParam.rcoupGoods)//添加 使用computed接收?? couponType:'864',
	// 		return new Promise(async (resolve, reject) => {
	// 			try {
	// 				console.log('getCoupons00');

	// 				let vres = await getVCoupons(source);	//专区券

	// 				let cres = await getCoupons(source);	//代金券
	// 				curSolve.value.curCoupon = cres
	// 				emit('change', curSolve.value)
	// 				console.log('getCoupons03', curSolve.value, vres, cres);
	// 				// let ures = await usableCouponList(props.nparam.rcoupGoods)
	// 				// hideLoading()
	// 				// if (res.result && res.object) {
	// 				// 	// resolve(r)
	// 				// } else {
	// 				// 	reject('');
	// 				// }
	// 			} catch (e) {
	// 				console.error(e)
	// 				reject(e);
	// 				hideLoading()
	// 				mApi.msg('网络繁忙，请稍后再试!')
	// 			}
	// 		});
	// 	}
	// 	navClass.value = 0

	// }
	// 代金券-s  
	const usableCount = ref(0)
	// const curCLass = ref(null)
	const coupParam = ref(null);
	const getCoupons = (ndata : any, source : any = '') => {
		coupParam.value = ndata;
		return new Promise(async (resolve, reject) => {
			try {
				usableCount.value = 0;
				console.log('getcoup',ndata)
				// props.nparam.rcoupGoods
				if (!ndata || !ndata.sku || (ndata.sku && ndata.sku.length <= 0)) {
					resolve('');
					return
				}
				let critem = tablist.value[0];
				critem.loaded = false;
				console.log('getCoupons000000', ndata);
				let ares = await getAutoCoupon(ndata)
				console.log('getCoupons01', ares);
				if(props.type != 'menu'&&(!ares.result || !ares.object || ares.object&&ares.object.usableCount <= 0)){
					hideLoading()
					critem.loaded = true;
					const nr = { nums: 0, usable: false };
					curCoupItem.value = nr;
					curSolve.value.curCoupon = nr;
					resolve(nr);
					return
				}
				if (ares.result && ares.object && ares.object.usableCount > 0) {
					// critem.loaded = true;
					usableCount.value = ares.object.usableCount;
					const atcoupon = ares.object.memberCouponVO || '';//{}
					
					let curItem:any= {};
					if (atcoupon) {
						curItem = {
							type: atcoupon.coupon_type || '',
							type_two: atcoupon.coupon_type_two || '',
							cId: atcoupon.ncoupon_id || '',
							mId: atcoupon.nmber_conpon_id || '',
							money: atcoupon.ncoupon_money || 0,
							sellCategory: atcoupon.sellCategory || '',
							disRate: atcoupon.par_value,
							skus: atcoupon.skus,
							nums: usableCount.value,//共多少张券-关联usable
							usable: true//是否可用代金券
						}
						curSolve.value.curCoupon = curItem;
						curCoupItem.value = curItem;
					}
					source == 'open' && showPop()
					console.log('getCoupons03+', curItem);
					resolve(curItem)
					
					
					
					// let ures = await usableCouponList(ndata)
					// console.log('getCoupons02', ures);
					// tablist.value[0].list = [];
					// if (ures.result && ures.object) {
					// 	critem.list = critem.list.concat(ures.object || [])
					// 	const cindex = critem.list.findIndex(item => item.nmber_conpon_id == atcoupon.nmber_conpon_id);
					// 	let curItem = {};
					// 	if (cindex >= 0) {
					// 		critem.list[cindex].select = true
					// 		const sitem = critem.list[cindex] || {};
					// 		curItem = {
					// 			type: sitem.coupon_type || '',
					// 			type_two: sitem.coupon_type_two || '',
					// 			cId: sitem.ncoupon_id || '',
					// 			mId: sitem.nmber_conpon_id || '',
					// 			money: sitem.ncoupon_money || 0,
					// 			sellCategory: sitem.sellCategory || '',
					// 			disRate: sitem.par_value,
					// 			skus: sitem.skus,
					// 			nums: usableCount.value,//共多少张券-关联usable
					// 			usable: true//是否可用代金券
					// 		}
					// 		curSolve.value.curCoupon = curItem;
					// 		curCoupItem.value = curItem;
					// 	}
					// 	source == 'open' && showPop()
					// 	console.log('getCoupons03+', curItem);
					// 	resolve(curItem)
					// } else {
					// 	mApi.msg(ures.shortMessage);
					// 	resolve('');
					// }
				} else {
					
					//获取代金券总数量
					// const tres = await totalCouponAmount({ channel: '1114' });
					// const ntres = tres.object || 0;
					// critem.loaded = ntres > 0 ? false : true;
					// const nr = { nums: ntres, usable: false };
					critem.loaded = true;
					const nr = { nums: 0, usable: false };
					curSolve.value.curCoupon = nr;
					curCoupItem.value = nr;
					// mApi.msg(ares.shortMessage);
					resolve(nr);
				}
			} catch (err) {
				console.error(err)
				mApi.msg('网络繁忙，请稍后再试!')
				reject(err);
				// hideLoading()
			}
		});
	}
	// 获取代金券列表
	const getCoupList = async(source:any='')=>{
		let critem = tablist.value[0];
		console.log(usableCount.value,props.coupUseMoney,"props.coupUseMoney")
		if(usableCount.value<=0||props.coupUseMoney<=0){
			critem.loaded = true;
			critem.list = [];
			return
		}
		// if(critem.loaded&&props.type == 'menu'&&props.coupUseMoney<=0){
		// 	hideLoading();
		// 	critem.loaded = true;
		// 	const nr = { nums: 0, usable: false };
		// 	curCoupItem.value = nr;
		// 	curSolve.value.curCoupon = nr;
		// 	resolve(nr);
		// 	return;
		// }
		try{
			// usableCount.value = ares.object.usableCount;
			// const atcoupon = ares.object.memberCouponVO || {};
			let ures = await usableCouponList(coupParam.value)
			critem.loaded = true;
			console.log('getCoupons02+', ures);
			tablist.value[0].list = [];
			if (ures.result && ures.object) {
				critem.list = critem.list.concat(ures.object || [])
				const cindex = critem.list.findIndex(item => curCoupItem.value.mId&&item.nmber_conpon_id == curCoupItem.value.mId);
				let curItem:any = {};
				if (cindex >= 0) {
					critem.list[cindex].select = true
					// const sitem = critem.list[cindex] || {};
					// curItem = {
					// 	type: sitem.coupon_type || '',
					// 	type_two: sitem.coupon_type_two || '',
					// 	cId: sitem.ncoupon_id || '',
					// 	mId: sitem.nmber_conpon_id || '',
					// 	money: sitem.ncoupon_money || 0,
					// 	sellCategory: sitem.sellCategory || '',
					// 	disRate: sitem.par_value,
					// 	skus: sitem.skus,
					// 	nums: usableCount.value,//共多少张券-关联usable
					// 	usable: true//是否可用代金券
					}
					// curSolve.value.curCoupon = curItem;
					// curCoupItem.value = curItem;
				}
				source == 'open' && showPop()
				console.log('getCouponsList+', critem.list);
		}catch(e){
			critem.loaded = true;
			console.error(e)
		}
		
	}
	const showMore = (item : any, type : any) => {
		item.show = !item.show
	}

	const loadStatus = ref('noMore')
	const pageInfo = ref({
		curPage: 1,
		pageSize: 10,
		backCupPage: 2
	})
	//代金券列表分页-查询所有代金券时
	const scrolltolower = () => {
		if(props.type == 'menu' && !curSolve.value.curCoupon.usable){
			getAllCoupList()
		}
	}
	
	// 获取当前所有代金券
	const getAllCoupList = async (source : any='add') => {
		loadStatus.value = 'loading'
		if (source == 'init' || source == 'open') {
			pageInfo.value.curPage = 1
			pageInfo.value.backCupPage = 2
		}
		if (pageInfo.value.curPage > pageInfo.value.backCupPage && source == 'add') {
			console.log("没有更多啦")
			loadStatus.value = 'noMore'
			return
		}
		source!='add'&&showLoading()
		let critem = tablist.value[0];
		try {
			critem.loaded = false;
			let res = await getCouponList({ channel: '1114', vstatus: '142', pageSize: pageInfo.value.pageSize, curPage: pageInfo.value.curPage })
			critem.loaded = true;
			hideLoading()
			if (!res.result || !res.object) {
				mApi.msg(res.shortMessage || '网络繁忙，请稍后再试', res.code)
				return
			}
			hideLoading()
			if (pageInfo.value.curPage == res.page.totalPage) {
				loadStatus.value = 'noMore'
			} else {
				loadStatus.value = 'more'
			}
			pageInfo.value.curPage += 1
			pageInfo.value.backCupPage = res.page.totalPage || 0

			if (source == 'init' || source == 'open') {
				critem.list = []
			}
			const nls = res.object.data || [];
			critem.list = critem.list.concat(nls)
			source == 'open' && showPop()
			// res.object.data.forEach((item : any, index : any) => {
			// 	const {
			// 		ncoupon_money,
			// 		coupon_type_two,
			// 		vname,
			// 		vend_date,
			// 		coupon_type,
			// 		vstatus,
			// 		ruleDesc,
			// 		scope_channel,
			// 		ext
			// 	} = item;
			// 	discountData.value.push({
			// 		id: index,
			// 		money: ncoupon_money,
			// 		type: coupon_type_two == '970' ? '0' : '1',
			// 		title: vname,
			// 		validity: `${vend_date.slice(0, 4)}.${vend_date.slice(4, 6)}.${vend_date.slice(6, 8)}`,
			// 		content: coupon_type == '870' ? '全场通用' : coupon_type == '869' ? '商品券' : coupon_type == '868' ? '现金券' : '',
			// 		select: false,
			// 		invalid: vstatus == '141' ? 1 : 0,
			// 		statue: vstatus,
			// 		ttyy: 0,
			// 		ruleDesc: ruleDesc,
			// 		scopChan: getScops(scope_channel),//该代金券在顿大侠是否能用
			// 		labels: ext.scope_channel_label||''
			// 	});
			// });
		} catch (e) {
			//TODO handle the exception
			critem.loaded = true;
			loadStatus.value = 'noMore'
			hideLoading()
		}
	}
	const curCoupItem = ref<any>({})
	//使用代金券
	const clipCoupons = (item : any) => {
		if (!usableCount.value) {
			return
		}
		
		let curItem = {}
		if (!item.select) {
			tablist.value[navClass.value].list.forEach(citem => {
				citem.select = false
			})
			curItem = {
				type: item.coupon_type || '',
				type_two: item.coupon_type_two || '',
				cId: item.ncoupon_id || '',
				mId: item.nmber_conpon_id || '',
				money: item.ncoupon_money || 0,
				sellCategory: item.sellCategory || '',
				disRate: item.par_value,
				skus: item.skus,
				usable: true,
				nums: tablist.value[navClass.value].list.length
			}
		} else {
			curItem = {
				type: '',
				type_two: '',
				cId: '',
				mId: '',
				money: 0,
				sellCategory: '',
				disRate: 1,
				skus: [],
				usable: true,
				nums: tablist.value[navClass.value].list.length
			}
		}
		curCoupItem.value = curItem;
		item.select = !item.select;


		// selectCount.value = discountData.value.filter((item) => item.select).length
	}
	const parseRate = (value : any) => {
		let num = 0;
		if (typeof value === 'number' && !isNaN(value)) {
			num = value * 100;
			num = num % 10 === 0 ? num / 10 : num
		}
		return parseInt(num)

	}
	// 代金券-e
	// 专区券-s
	const vcouponDetail = ref<any>({})//专区券详情
	const vipCountData = computed(() => {
		let num = 0,
			allTotalMoney = 0,
			totalMoney = 0,
			amout = 0,
			sList = [];
		tablist.value&&tablist.value[1]&&tablist.value[1].list.forEach(item => {
			allTotalMoney += item.faceMoney * item.storeNums
			item.selectNums > 0 ? (num += item.selectNums) : "";
			item.selectNums > 0 ? (totalMoney += item.faceMoney * item.selectNums) : "";
			if (item.selectNums > 0) {
				item.selectNums && sList.push(item)
			}
		});
		amout = totalMoney < vcouponDetail.value.totalPrice ? 0 : vcouponDetail.value.totalBackPrice;
		let slc = {
			totalNum: num,
			sList: sList,
			canUse: canUseVip.value,
			title: '已选VIP专区券使用明细',
			totalMoney: totalMoney,//已选券总金额
			disVAmout: amout||0,
			allTotalMoney: allTotalMoney,//专区券可用总金额
			allowVipTotalPrice: vcouponDetail.value.allowVipTotalPrice || 0,
			totalVipPrice: vcouponDetail.value.totalVipPrice||0//vip商品总额
		};
		console.log('vipCountData3',slc, totalMoney > 0,totalMoney >= vcouponDetail.value.totalPrice);
		return slc;
	})
	const canUseVip = ref(false);//是否可用资格券
	//获取资格券
	const getVCoupons = (source) => {		
		return new Promise(async (resolve, reject) => {
			let critem = tablist.value[1];
			try {
				let ndata : any = {};
				if (cartStore.curOrderType && cartStore.curOrderType.type) {
					ndata.patten = cartStore.curOrderType.type;
					ndata.subsTime = cartStore.curOrderType.time.dateString
				}
				tablist.value[1].list = [];
				critem.loaded = false;
				let vres = await getVipAccount(ndata)
				console.log('getVCoupons01', vres);
				// hideLoading()
				// tablist.value[1].list = [];
				critem.loaded = true
				canUseVip.value = false;
				if (vres.result && vres.object) {
					vcouponDetail.value = vres.object || {};
					critem.list = vres.object.credCoupons || [];
					let num = 0,
						allTotalMoney = 0,
						
						totalMoney = 0,
						amout = 0,
						sList = [];
						let newStr=critem.list.map((item:any) => item.faceMoney).join('')
						let redEnv = shopStore.changeCoups&&shopStore.changeCoups.length>0?shopStore.changeCoups.find((item:any) => item.id == '1'):[]
						let oldStr= redEnv&&redEnv.list&&redEnv.list.length>0 ? redEnv.list.map((item:any) => item.faceMoney).join('') : '';
						if(newStr==oldStr){
							critem.list = critem.list.map((item:any) => {
							   item.selectNums>0?canUseVip.value = true:''
							    let oldItem = redEnv.list.find((old:any) => old.faceMoney == item.faceMoney);
							    if (oldItem) {
							        item.selectNums = item.storeNums >= oldItem.selectNums ? oldItem.selectNums : item.selectNums;
							    }
							    return item;
							});
						}
					critem.list.forEach(item => {
						allTotalMoney += item.faceMoney * item.storeNums;
						item.selectNums>0&&newStr!=oldStr?canUseVip.value = true:'';
						item.selectNums > 0 ? (num += item.selectNums) : "";
						item.selectNums > 0 ? (totalMoney += item.faceMoney * item.selectNums) : "";
						if (item.selectNums > 0) {
							item.selectNums && sList.push(item);
						}
					});
				
       
					amout = totalMoney < vcouponDetail.value.totalPrice ? 0 : vcouponDetail.value.totalBackPrice;
					let slc = {
						totalNum: num,
						sList: sList,
						canUse: canUseVip.value,
						title: '已选VIP专区券使用明细',
						totalMoney: totalMoney,//vip商品可用金额同allowVipTotalPrice
						disVAmout: amout,
						allTotalMoney: allTotalMoney,//专区券总额
						allowVipTotalPrice: vcouponDetail.value.allowVipTotalPrice || 0,
						totalVipPrice: vcouponDetail.value.totalVipPrice//vip商品总额
						// canDisAmout:amout
					};
					source == 'open' && showPop()
					resolve(slc)
					console.log('getVCoupons02', vres, vipCountData);

				} else {
					source == 'open' && showPop();
					props.type!='menu'&&mApi.msg(vres.shortMessage||'网络繁忙，请稍后再试');
					resolve('');
				}
			} catch (e) {
				source == 'open' && showPop();
				critem.loaded = true;
				console.error(e)
				reject(e);
				// hideLoading()
				mApi.msg('网络繁忙，请稍后再试!')
			}
		});
	}
	// 点击已选
	const tapShowSelc = () => {
		// dataType.value='slect'
		// navClass.value == 1 && slecmd.value.open()

		if (vipCountData.value.totalNum === 0 || navClass.value == 0) return
		slecmd.value.open(vipCountData.value.sList)
	}
	// 查看明细
	const tapCheckDetail = (faceMoney : any) => {
		vcdetmd.value.open(faceMoney)
	}
	const changeNum = (e : any) => { }
	// 专区券-e
	
	// 选中默认券
	const initCoupSelect = ()=>{
		let item = tablist.value[0];
		if(item.loaded&&usableCount.value>0&&curSolve.value.curCoupon&&curSolve.value.curCoupon.mId){
			item.list.forEach(citem=>{
				console.log('ffffooo',citem.nmber_conpon_id,citem.nmber_conpon_id==curSolve.value.curCoupon.mId);
				citem.select = (citem.nmber_conpon_id==curSolve.value.curCoupon.mId?true:false);
			})
		}
		
	}
	// 获取券列表
	const getCouList = (param, source) => {
		// props.type=='menu'&&!curSolve.value.curCoupon.usable&&nums
		let item = tablist.value[navClass.value];
		if (item.loaded) {
			// 默认选中券
			showPop();
			return
		}
		getCoupList(source)
		// getCoupons(param, source)
		// props.type == 'menu' && !curSolve.value.curCoupon.usable ? getAllCoupList(source) : getCoupons(param, source);
	}
	const open = (index : any=0) => {
		if(props.type == 'menu'&&sellMemberInfo.value.ids!=shopStore.curSellerMemberId&&tablist.value&&tablist.value[1]){
			tablist.value[1].loaded=false
			
		}
		sellMemberInfo.value.ids==shopStore.curSellerMemberId
		// console.log('opencoupon', index, tablist.value[index].loaded);
		navClass.value = index;
		// console.log('open',index,tablist.value[1])
		initCoupSelect();
		index == 0 ? getCouList(coupParam.value, 'open') : getVCoupons('open');
		// index==0&&tablist.value[index].loaded?showPop():'';

	}
	const showPop = () => {

		reserve.value.open();
		tabsRef.value.init();
	}
	const close = () => {
		reserve.value.close()
		emit('updateValueFn', 10)
	}
	// 确认
	const confirm = () => {
		// const curSolve = ref<any>({
		// 	curCoupon: {},
		// 	curVCoupon: {},
		// })
		// vipCountData
		curSolve.value.curCoupon = curCoupItem.value;
		curSolve.value.curVCoupon = vipCountData.value;
		if(vipCountData.value.canUse){
			shopStore.setChangeCoups(JSON.parse(JSON.stringify(tablist.value)))
		}else{
			let nlist = JSON.parse(JSON.stringify(tablist.value))
			shopStore.setChangeCoups(nlist.pop())
		}
		emit('change', curSolve)

		reserve.value.close()
	}



	const navClass = ref(0)
	// let deepCloneDemo = JSON.parse(JSON.stringify(discountData.value))
	const tabSelect = (item : any, index : any = 0) => {
		// discountData.value = deepCloneDemo.filter(i => i.id == item.id)
		navClass.value = index;
		console.log('tab', tablist.value[index], item)
		if (!tablist.value[index].loaded&&sellMemberInfo.value.ids!=shopStore.curSellerMemberId) {
			index == 0 ? getCouList(coupParam.value, 'init') : getVCoupons('init');
		}

	}

	defineExpose({ open, close, getVCoupons, getCoupons })
</script>

<style lang="scss" scoped>
	// .padding-top-zdy {
	// 	padding-top: 30rpx;
	// }

	.justiftRight {
		justify-content: flex-end !important;
	}

	.tip-con {
		height: 64rpx;
		border-radius: 4px;
		background: #fff4e4;
		box-shadow: 0px -2px 4px 0px rgba(0, 0, 0, 0.1);
		width: 100%;
		position: absolute;
		padding-left: 16rpx;
		left: 0;
		bottom: 130rpx;
		z-index: 99;

		.font-infofill {
			color: #ff9700;
			font-family: 'Microsoft YaHei UI';
			font-size: 14px;
			font-style: normal;
			font-weight: 400;
			line-height: normal;
			letter-spacing: -0.25px;
		}

		.cuIcon-infofill-style {
			color: #ff9700;
			margin-right: 10rpx;
		}
	}

	.ttyyTextStyle {
		color: #ff6868;
		font-family: 'Microsoft YaHei UI';
		font-size: 28rpx;
		font-style: normal;
		font-weight: 400;
		line-height: normal;
	}

	.carListBox {
		width: 100vw;
		// padding:0rpx 20rpx 0rpx 0rpx;
		background-color: #fff;
		border-radius: 20rpx 20rpx 0rpx 0rpx;

		.belivery-title {
			color: #333;
			font-size: 40rpx;
			font-weight: 700;
			margin: 30rpx 0rpx 30rpx 30rpx;
		}

		.tabs_box {
			width: 100%;
			min-height: 45rpx;
			padding: 0rpx 20rpx 0rpx 20rpx;
		}

		.uni-bar-wbg {
			height: 690rpx;

			// overflow-y: scroll;
			.uni-bar-w {
				min-height: 520rpx;
			}

			.cu-bar-yhj {
				width: 90%;
				border-radius: 8rpx;
				background: #fff;
				box-shadow: 0px 0px 10px 0px rgba(212, 219, 238, 0.8);
				// min-height: 180.744rpx;
				// display: flex;
				// justify-content: space-between;
				margin-bottom: 30rpx;
				align-items: center;
				transition: all 0.5s;
				margin-left: 46rpx;
				margin-top: 20rpx;
				position: relative;

				// &:last-child{
				//   margin-bottom: 0;
				// }
				.cu-bar-yhj-right {
					display: flex;
					align-items: center;
					margin-right: -15rpx;

					.cu-bar-yhj-rightBtn {
						width: 142rpx;
						height: 72rpx;
						border-radius: 36rpx;
						background: #e4f8e4;
						display: flex;
						justify-content: center;
						align-items: center;
						font-size: 28rpx;
						color: #56bf7a;
					}
				}

				.cu-bar-yhj-left {
					display: flex;

					.cu-bar-yhj-left-text {
						justify-content: space-between;
						padding-left: 20rpx;
						margin-right: 30rpx;
						padding-bottom: 10rpx;
						position: relative;
						display: flex;
						flex-direction: column;
						flex: 1;
						border-bottom: 1px solid #fff0f0;

						.activeWy {
							transform: translateY(0%) !important;
							opacity: 1 !important;
							height: auto !important;
							transition: all 0.1s ease-out;
						}

						.rule-con-ul {
							overflow: hidden;
						}

						.ruleconulptop {
							padding-top: 20rpx;
						}

						.rule-con {
							width: 100%;
							color: #999;
							// margin-top: 10rpx;
							// margin-bottom: 6rpx;
							// font-family: "Microsoft YaHei UI";
							font-size: 24rpx;
							// font-weight: 400;
							// line-height: normal;
							letter-spacing: 0.24px;
							transform: translateY(-120%);
							transition: all 0.5s;
							height: 0;
							opacity: 0;
							// transform: scale(0);
							// transition: all .5s;
						}

						.ruleActive {
							// height: 100%;
							transform: scale(1);
						}
					}

					.cu-bar-yhj-Pic {
						display: flex;
						align-items: center;
						justify-content: center;
						flex-direction: column;
						min-width: 202rpx;
						border-radius: 4px 0px 0px 4px;
						position: relative;
						padding: 20rpx 0;
						// background: url('https://cdn-static.yekjx.com/food/images/car_img08.png');
						// background-repeat: repeat-y;
						background-color: #fff0f0;
						z-index: 12;

						&::before {
							content: '';
							width: 20rpx;
							height: 100%;
							position: absolute;
							right: -7rpx;
							top: 0;
							background-size: 25rpx 25rpx;
							background-image: radial-gradient(#fff 6rpx, transparent 6rpx);
							background-repeat: repeat-y;
						}
					}

					.cu-bar-yhj-PicStyle {
						color: #ff6868;
						font-size: 60rpx;
						font-weight: 700;

						.cu-bar-yhj-PicZk {
							font-weight: 400;
							// margin-left: -10rpx;
							font-size: 24rpx;
						}
					}

					.cu-bar-yhj-min {
						color: #ff6868;
						font-size: 24rpx;
						font-weight: 400;
						letter-spacing: 0.24px;
					}

					.cu-bar-yhj-left-text {
						display: flex;
						flex-direction: column;
						padding-top: 20rpx;

						.cu-bar-yhj-title {
							color: #333;
							font-size: 32rpx;
							font-weight: 700;
						}

						.cu-bar-yhj-titleNew {
							color: #333;
							font-family: "Microsoft YaHei UI";
							font-size: 32rpx;
							font-weight: 400;


						}

						.cu-bar-yhj-left-time {
							color: #666;
							font-size: 28rpx;
							font-weight: 400;
							margin-top: 10rpx;
						}

						.cu-bar-yhj-left-ruleckmx {
							padding-bottom: 10rpx;
						}

						.cu-bar-yhj-left-rule {
							color: #999;
							font-size: 24rpx;
							font-weight: 400;
							display: inline-block;
						}

						.inblcok {
							display: inline-block;
						}

						.routerHover {
							transform: rotate(180deg);
						}
					}
				}
			}
		}

		.discount-footer {
			height: 130rpx;
			background: #fff;
			// box-shadow: 0px 0px 5px 0px rgba(0, 0, 0, 0.05);
			align-items: center;
			padding: 0 20rpx;
			justify-content: space-between;
			display: flex;
			margin-left: 20rpx;
			position: relative;

			.discount-footer-l {
				color: #666;
				font-size: 32rpx;

				.discount-c-r {
					color: #ff6868;
					margin: 0 5rpx;
				}
			}

			.discount-footer-r {
				.sub_btn {
					width: 398rpx;
					height: 90rpx;
					display: flex;
					flex-shrink: 0;
					align-items: center;
					justify-content: center;
					border-radius: 10rpx;
					background: #53a87f;
					color: #fff;
					font-size: 32rpx;
					font-weight: 700;
				}
			}
		}
	}

	.justifyEend {
		justify-content: flex-end !important;
	}

	.selcbx {
		height: 70rpx;

		.yxuanText {
			color: #999;
			font-family: "Microsoft YaHei UI";
			font-size: 28rpx;
			margin-left: 20rpx;
			font-weight: 400;
		}
	}
</style>